package com.devhelper.examples.gef.part;

import java.beans.PropertyChangeEvent;
import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;

import com.devhelper.examples.gef.figure.DepartmentFigure;
import com.devhelper.examples.gef.model.Department;
import com.devhelper.examples.gef.model.Node;
import com.devhelper.examples.gef.policy.ExEditLayoutPolicy;

public class DepartmentEditPart extends ExAbstractEditPart {

    @Override
    protected IFigure createFigure() {
        return new DepartmentFigure();
    }

    @Override
    protected void createEditPolicies() {
        installEditPolicy(EditPolicy.LAYOUT_ROLE, new ExEditLayoutPolicy());
    }

    @Override
    protected void refreshVisuals() {
        DepartmentFigure figure = (DepartmentFigure) getFigure();
        Department model = (Department) getModel();

        figure.setName(model.getName());
        figure.setCount(model.getCount());
        figure.setLayout(model.getLayout());
    }

    @Override
    public List<Node> getModelChildren() {
        return ((Department) getModel()).getChildren();
    }

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        if (evt.getPropertyName().equals(Node.PROPERTY_LAYOUT)) {
            refreshVisuals();
        }
    }
}
